/*------------------------------------------------------*/
/* data dispatcher define                               */
/*                                                      */
/* datadispatch.h                                       */
/*                                                      */
/* Copyright (C) CyberNaut.com.cn                       */
/* All rights reserved                                  */
/*                                                      */
/* Author                                               */
/*    Jobs Chen (jobs.chen@cybernaut.com.cn)            */
/*                                                      */
/* History                                              */
/*    03/23/2006  Create                                */
/*                                                      */
/*------------------------------------------------------*/

#ifndef __CM_DATA_DISPATCH_H__
#define __CM_DATA_DISPATCH_H__

#include "sessbase.h"

class IUserSAP;
class IUserSAPSink;

class IDataDispatchProviderSink;

class IDataDispatcherProvider
{
public:
	static IDataDispatcherProvider* Instant();

	virtual CmResult Register(
				CM_SESS_TYPE nType,
				IDataDispatchProviderSink* pSink) = 0;

	virtual CmResult UnRegister(CM_SESS_TYPE nType,
							IDataDispatchProviderSink* pSink) = 0;			
	
	virtual CmResult Listen(const TransportAddress& aAddress) = 0;
	
	virtual CmResult Connect(IDataDispatchProviderSink* pSink,
						DWORD dwAddressNumber,
						TransportAddress* addrs,
						CM_SESS_TYPE	nType,
						 DomainID_Type confID,
						 DWORD dwLength,
						 LPBYTE	user_data,
						 int  nFlag,//whether share with other, 
						 TransportHandle& hHandle ) = 0;
	
	virtual CmResult ConnectResponse(TransportHandle hHandle,
					DomainID_Type domainID,
					CM_SESS_TYPE nType,
					CmResult	nResult,
					DWORD		dwLength,
					LPBYTE		lpData) = 0;

								 
	virtual CmResult Disconnect(TransportHandle& handle) = 0;
	
	virtual CmResult CreateDomain(DomainID_Type domainID) = 0;
	
	virtual CmResult DestroyDomain(DomainID_Type domainID) = 0;

	virtual CmResult CreateChanel(DomainID_Type domainID, CSessChannelID& channelID) = 0;

	virtual CmResult DestroyChannel(const CSessChannelID& channelID) = 0;

	virtual CmResult AttachUser(DomainID_Type domainID,
					IUserSAPSink*	pSink,
					IUserSAP*&	pSAP) = 0;
					
};

class IDataDispatchProviderSink
{
public:
	virtual void OnTransportReady(TransportHandle hHandle,
					DomainID_Type domainID,
					CM_SESS_TYPE	nType,
					DWORD		dwLength,
					LPBYTE		lpUserData) = 0;
					
	virtual void OnTransportConfirm(TransportHandle hHandle,
					CmResult nResult,
					DWORD	dwLength,
					LPBYTE	lpUserData) = 0;
					
	virtual void OnTransportDestroy(TransportHandle hHandle,
					CmResult nReason) = 0;//nReason: 0, all closed, 1: primary closed?
	
};
									
class IUserSAP
{
public:
	virtual const CSessUserID& GetUserID() const = 0;
	virtual CmResult DetachUser() = 0;
	virtual CmResult JoinChannel(const CSessChannelID& channelID) = 0;
	virtual CmResult LeaveChannel(const CSessChannelID& channelID) = 0;
	virtual CmResult SendData(const CSessChannelID& channelID,
								DATA_PRIORITY	nPriority,
								BOOL	bCommand,
								CCmMessageBlock& msg) = 0;
};

class IUserSAPSink
{
public:
	virtual void OnDetachUserIndication(CmResult nReason,
						const CSessUserID& userID) = 0;
	virtual void OnJoinChannelConfirm(CmResult nResult,
						const CSessChannelID& channelID) =0;
	virtual void OnLeaveChannelIndication(CmResult nReason,
						const CSessChannelID& channelID) = 0;
	
	virtual void OnReceiveData(const CSessUserID& SenderID,
				const CSessChannelID&	channelID,
				DATA_PRIORITY nPriority,
				BOOL bCommand,
				CCmMessageBlock& msg) = 0;					
};

#endif


						